package org.jeecg.modules.lab.skill.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.lab.skill.entity.LabUserSkill;
import org.jeecg.modules.lab.skill.service.ILabUserSkillService;
import org.jeecg.modules.lab.skill.vo.LabUserSkillPage;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

 /**
 * @Description: 实验人员专业能力表
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Api(tags="实验人员专业能力表")
@RestController
@RequestMapping("/skill/labUserSkill")
@Slf4j
public class LabUserSkillController extends JeecgController<LabUserSkill, ILabUserSkillService> {
	@Autowired
	private ILabUserSkillService labUserSkillService;
	
	/**
	 * 分页列表查询
	 *
	 * @param labUserSkill
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="实验人员专业能力表-分页列表查询", notes="实验人员专业能力表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<LabUserSkill>> queryPageList(LabUserSkill labUserSkill,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="200") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<LabUserSkill> queryWrapper = QueryGenerator.initQueryWrapper(labUserSkill, req.getParameterMap());
		Page<LabUserSkill> page = new Page<LabUserSkill>(pageNo, pageSize);
		IPage<LabUserSkill> pageList = labUserSkillService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param labUserSkill
	 * @return
	 */
//	@AutoLog(value = "实验人员专业能力表-添加")
	@ApiOperation(value="实验人员专业能力表-添加", notes="实验人员专业能力表-添加")
//	@RequiresPermissions("skill:lab_user_skill:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody LabUserSkill labUserSkill) {
		labUserSkillService.save(labUserSkill);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param labUserSkill
	 * @return
	 */
//	@AutoLog(value = "实验人员专业能力表-编辑")
	@ApiOperation(value="实验人员专业能力表-编辑", notes="实验人员专业能力表-编辑")
//	@RequiresPermissions("skill:lab_user_skill:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody LabUserSkill labUserSkill) {
		labUserSkillService.updateById(labUserSkill);
		return Result.OK("编辑成功!");
	}

	 /**
	  *  更新专业能力
	  * @param labUserSkillPage
	  * @return
	  */
//	 @AutoLog(value = "实验人员专业能力表-更新专业能力")
	 @ApiOperation(value="实验人员专业能力表-更新专业能力", notes="实验人员专业能力表-更新专业能力")
	 @RequestMapping(value = "/updateUserSkills", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> updateUserSkills(@RequestBody LabUserSkillPage labUserSkillPage) {
		 labUserSkillService.updateSkills(labUserSkillPage);
		 return Result.OK("保存成功!");
	 }


	 /**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
//	@AutoLog(value = "实验人员专业能力表-通过id删除")
	@ApiOperation(value="实验人员专业能力表-通过id删除", notes="实验人员专业能力表-通过id删除")
//	@RequiresPermissions("skill:lab_user_skill:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		labUserSkillService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
//	@AutoLog(value = "实验人员专业能力表-批量删除")
	@ApiOperation(value="实验人员专业能力表-批量删除", notes="实验人员专业能力表-批量删除")
//	@RequiresPermissions("skill:lab_user_skill:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@NotNull @RequestParam(name="ids",required=true) String ids) {
		this.labUserSkillService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "实验人员专业能力表-通过id查询")
	@ApiOperation(value="实验人员专业能力表-通过id查询", notes="实验人员专业能力表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<LabUserSkill> queryById(@RequestParam(name="id",required=true) String id) {
		LabUserSkill labUserSkill = labUserSkillService.getById(id);
		if(labUserSkill==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(labUserSkill);
	}


//	 @AutoLog(value = "实验人员专业能力表-专业能力复制")
	 @ApiOperation(value="实验人员专业能力表-专业能力复制", notes="实验人员专业能力表-专业能力复制")
	 @RequestMapping(value = "/copyUserSkill", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> copyUserSkill(@RequestParam(name="oldUserId",required=true) String oldUserId,@RequestParam(name="newUserId",required=true) String newUserId) {
		 labUserSkillService.copyUserSkill(oldUserId,newUserId);
		 return Result.OK("复制成功!");
	 }


	 /**
	  *  新专业能力
	  * @return
	  */
	 @ApiOperation(value="实验人员专业能力表-新专业能力", notes="实验人员专业能力表-新专业能力")
	 @RequestMapping(value = "/newXUserSkills", method = {RequestMethod.POST})
	 public Result<String> newXUserSkills() {
		 labUserSkillService.newDataSkill();
		 return Result.OK("保存成功!");
	 }

    /**
    * 导出excel
    *
    * @param request
    * @param labUserSkill
    */
//    @RequiresPermissions("skill:lab_user_skill:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, LabUserSkill labUserSkill) {
        return super.exportXls(request, labUserSkill, LabUserSkill.class, "实验人员专业能力表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
//    @RequiresPermissions("skill:lab_user_skill:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, LabUserSkill.class);
    }

}
